﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class RoyalItemRepayDetailBLL : IRoyalItemRepayDetailBLL
    {
        private static readonly IRoyalItemRepayDetailDAL dal = DataAccess.CreateRoyalItemRepayDetails();

        private RoyalItemRepayInfo detailInfo = new RoyalItemRepayInfo();
        private RoyalItemRepayInfo parentInfo = new RoyalItemRepayInfo();
        private RoyalItemInfo itemInfo = new RoyalItemInfo();
        private MasGenderInfo genderInfo = new MasGenderInfo();

        public IList<RoyalItemRepayInfo> ListRoyalItemRepayDetails(int Parent)
        {
            parentInfo.Sequence = Parent;
            return dal.ListRoyalItemRepayDetails(new RoyalItemRepayInfo(0, parentInfo, itemInfo, genderInfo, 0, "", "", 0, 0));
        }
        public IList<RoyalItemRepayInfo> ListRoyalItemRepayDetailsBySequence(int Sequence)
        {
            return dal.ListRoyalItemRepayDetails(new RoyalItemRepayInfo(Sequence));
        }

        public void Insert(int Parent, string RoyalItem, string Gender, decimal Amount, string Remarks, int CreatedBy)
        {
            parentInfo.Sequence = Parent;
            itemInfo.Sequence = RoyalItem.Length > 0 ? Int32.Parse(RoyalItem) : 0;
            genderInfo.Sequence = Gender.Length > 0 ? Int32.Parse(Gender) : 0;

            try
            {
                dal.Insert(new RoyalItemRepayInfo(0, parentInfo, itemInfo, genderInfo, Amount, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }

        }
        public void Update(int Sequence, int Parent, string RoyalItem, string Gender, decimal Amount, string Remarks, int UpdatedBy)
        {
            parentInfo.Sequence = Parent;
            itemInfo.Sequence = RoyalItem.Length > 0 ? Int32.Parse(RoyalItem) : 0;
            genderInfo.Sequence = Gender.Length > 0 ? Int32.Parse(Gender) : 0;

            try
            {
                dal.Update(new RoyalItemRepayInfo(Sequence, parentInfo, itemInfo, genderInfo, Amount, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }

        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
